

const queue:any[] = [];
let isFLushPending = false;

export function nextTick(fn){
    return fn?Promise.resolve().then(fn):Promise.resolve();
}

export function queueJobs(job){
    if (!queue.includes(job)){
        queue.push(job);
    }

    queueFlush();
}

function queueFlush() {
    if (isFLushPending) return;
    isFLushPending = true;
    nextTick(flushJobs)
}
function flushJobs() {
    isFLushPending = false;
    let job;
    while ((job = queue.shift())) {
        job && job();
    };
}

